package com.fiona.register.zk;

import org.apache.curator.framework.CuratorFramework;

import com.fiona.common.base.config.RpcConfig;
import com.fiona.common.constant.FionaConstant;
import com.fiona.core.remoting.model.Service;
import com.fiona.register.api.AbstractServiceRegister;
import com.fiona.register.zk.util.CuratorUtils;

/**
 * service registration based on zookeeper
 *
 */
public class ZkServiceRegistry extends AbstractServiceRegister {

	public void doRegister(Service so) {
		// /Fiona/pay/com.fiona.example.service.HelloService/serviceName1/1.0.0/127.0.0.1:9999
		String servicePath = CuratorUtils.ZK_REGISTER_ROOT_PATH + FionaConstant.BACKSLASH + RpcConfig.getGroup()
				+ FionaConstant.BACKSLASH + so.getUri();
		CuratorFramework zkClient = CuratorUtils.getZkClient();
		CuratorUtils.createPersistentNode(zkClient, servicePath);
	}

}
